% =========================================================================
% function estimaParallel
% estimaParallel
% Controls settings for parallelization of the estima codes 
% Key output poolObj, used to initialize the worker pool 
%
% Requires 
% flags.unix 
%       .parallel
%       .desktop 
%       .quincy 
% 
% A. Justiniano Feb 18 2014 
% =========================================================================
if flags.unix==1;
    onscreen=0;
    addtools;
end

if flags.parallel==1
    if matlabpool('size')>0
        matlabpool close
    end
    if matlabpool('size')==0 && flags.unix == 0
        if flags.quincy==0 && flags.desktop==0
            disp('Running Parallel on Miyajima');
            poolObj=parpool(12);
        elseif flags.quincy==1
            disp('Running Parallel on Quincy');
            poolObj=parpool(8);
        else
            poolObj=parpool(2);
            disp('Running Parallel on Desktop');
        end
    elseif matlabpool('size')==0 && flags.unix == 1
        matlabpool open % it will use a pre-existing configuration called "Alejandro"
    end
end
